package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "UserByIDServlet")
public class UserByIDServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        String id=request.getParameter("userid");
        IDAO dao=new UserDao();
        Users users=null;
        HttpSession session=request.getSession();

        List<Users> list=(List)session.getAttribute("allusers");
        for(Users u:list){
            if (u.getEu_user_id().equals(id)){
                users=u;
                break;
            }
        }

//        try {
//            users=((UserDao) dao).getUsersByID(id);
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
        request.setAttribute("userByID",users);
        request.getRequestDispatcher("manager/user-modify.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
